﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Bricks.MiuiThemeMaker.BaseFramework.Converters
{
    /// <summary>
    /// 取反值Converter，true转为false，false转为true
    /// </summary>
    [ValueConversion(typeof(bool), typeof(bool))]
    public class TrueToFalseConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return BooleanComplement(value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return BooleanComplement(value);
        }

        /// <summary>
        /// 取反值
        /// </summary>
        private bool BooleanComplement(object value)
        {
            if (value is bool)
            {
                bool source = (bool)value;
                //取反值
                return !source;
            }
            else
            {
                throw new ArgumentException("value 必须为bool类型.");
            }
        }
    }
}
